<template>
  <div  class="waper">
    <el-row :gutter="20">
      <el-col :span="24">
          <h2>拖拽模块</h2>
      </el-col>
      <el-col :span="24">
          <div class="drag-box">
                <div class="drag-box-item">
                    <div class="item-title">todo</div>
                    <draggable v-model="todo" @remove="removeHandle" :options="dragOptions" @update="datadragEnd">
                        <transition-group tag="div" id="todo" class="item-ul">
                            <div v-for="item in todo" class="drag-list" :key="item.id">
                                {{item.content}}
                            </div>
                        </transition-group>
                    </draggable>
                </div>
                <div class="drag-box-item">
                    <div class="item-title">doing</div>
                    <draggable v-model="doing" @remove="removeHandle" :options="dragOptions">
                        <transition-group tag="div" id="doing" class="item-ul">
                            <div v-for="item in doing" class="drag-list" :key="item.id">
                                {{item.content}}
                            </div>
                        </transition-group>
                    </draggable>
                </div>
                <div class="drag-box-item">
                    <div class="item-title">done</div>
                    <draggable v-model="done" @remove="removeHandle" :options="dragOptions">
                        <transition-group tag="div" id="done" class="item-ul">
                            <div v-for="item in done" class="drag-list" :key="item.id">
                                {{item.content}}
                            </div>
                        </transition-group>
                    </draggable>
                </div>
            </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import draggable from 'vuedraggable'
export default {
  data () {
    return {
            dragOptions:{
                animation: 120,
                scroll: true,
                group: 'sortlist',
                ghostClass: 'ghost-style'
            },
            todo: [
                {
                  id: 1,
                  content: '开发图表组件'
                },
                {
                  id: 2,
                  content: '开发拖拽组件'
                },
                {
                  id: 3,
                  content: '开发权限测试组件'
                }
            ],
            doing: [
                {
                  id: 1,
                  content: '开发登录注册页面'
                },
                {
                  id: 2,
                  content: '开发头部组件'
                },
                {
                  id: 3,
                  content: '开发表格相关组件'
                },
                {
                  id: 4,
                  content: '开发表单相关组件'
                }
            ],
            done:[
                {
                  id: 1,
                  content: '初始化项目，生成工程目录，完成相关配置'
                },
                {
                  id: 2,
                  content: '开发项目整体框架'
                }
            ]
    }
  },
  components:{
      draggable
  },
  methods: {
            removeHandle(event){
                console.log(this.todo)
                console.log(event);
                this.$message.success(`从 ${event.from.id} 移动到 ${event.to.id} `);
            },
            datadragEnd(evt){
                console.log('拖动前的索引：' + evt.oldIndex);
                console.log('拖动后的索引：' + evt.newIndex);
                console.log(evt)
                console.log(this.todo)
            }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
  text-align: left;
  margin-bottom: 30px;
}
    .drag-box{
        display: flex;
        user-select: none;
    }
    .drag-box-item {
        flex: 1;
        max-width: 330px;
        min-width: 300px;
        background-color: #eff1f5;
        margin-right: 16px;
        border-radius: 6px;
        border: 1px #e1e4e8 solid;
    }
    .item-title{
        padding: 8px 8px 8px 12px;
        font-size: 14px;
        line-height: 1.5;
        color: #24292e;
        font-weight: 600;
    }
    .item-ul{
        padding: 0 8px 8px;
        height: 500px;
        overflow-y: scroll;
    }
    .item-ul::-webkit-scrollbar{
        width: 0;
    }
    .drag-list {
        border: 1px #e1e4e8 solid;
        padding: 10px;
        margin: 5px 0 10px;
        list-style: none;
        background-color: #fff;
        border-radius: 6px;
        cursor: pointer;
        -webkit-transition: border .3s ease-in;
        transition: border .3s ease-in;
    }
    .drag-list:hover {
        border: 1px solid #20a0ff;
    }
    .drag-title {
        font-weight: 400;
        line-height: 25px;
        margin: 10px 0;
        font-size: 22px;
        color: #1f2f3d;
    }
    .ghost-style{
        display: block;
        color: transparent;
        border-style: dashed
    }
</style>
